package philosoph;

import log.*;

public class StdPhilosoph implements Philosoph {

	private static int seed;

	private int thinkTime;
	private int eatTime;
	private final int iD;
	private Logger logger = new NullLogger();

	public StdPhilosoph(int thinkTime, int eatTime) {
		this.thinkTime = thinkTime;
		this.eatTime = eatTime;
		this.iD = seed++;
	}

	public StdPhilosoph(int thinkTime, int eatTime, Logger logger) {
		this(thinkTime, eatTime);
		this.logger = logger;
	}

	@Override
	public void think() throws InterruptedException {
		this.logger.log(-1, "Philosoph Nr. " + String.format("%4d", this.iD) + " thinks.");
		Thread.sleep(this.thinkTime);
		this.logger.log(-1, "Philosoph Nr. " + String.format("%4d", this.iD) + " is hungry.");
	}

	@Override
	public void eat() throws InterruptedException {
		this.logger.log(-1, "Philosoph Nr. " + String.format("%4d", this.iD) + " eats.");
		Thread.sleep(this.eatTime);
		this.logger.log(-1, "Philosoph Nr. " + String.format("%4d", this.iD) + " is finished.");
	}

	@Override
	public int hashCode() {
		return this.iD;
	}

	@Override
	public boolean equals(Object obj) {
		return this == obj; // for speed reasons
	}

}
